$(document).ready(function(){
	/*搜索按钮-显示搜索详情*/
	var ctx=$("#inputCtx").val();
	$("#btnSearch01").click(function (){
		var bespeakNumber=$.trim($("#searchBespeakNumber").val());
		if((new String(bespeakNumber)).length!=11){
			 layer.tips('请填写正确的预约编码', '#searchBespeakNumber', {
			   tips: [1, '#0FA6D8']
			});
			return false;
		}
		showBespeakDetail(bespeakNumber);
	});

	/*关闭详情显示*/
	$("#btnClose01").click(function (){
		$("#showMsg01").css("display","none");
		$("#searchBespeakNumber").val("");
	});
	
	/*律师预约*/
	$("#btnLawBespeak").click(function (){
		var url=ctx+"/visitor/law";
		/*iframe窗*/
		showSmallWindow('律师预约',url,'930px', '580px');
	});
	
	/*公检法预约*/
	$("#btnCheckBespeak").click(function (){
		var url=ctx+"/visitor/check";
		/*iframe窗*/
		showSmallWindow('公检法预约',url,'930px', '580px');		
	});
	
	/*预约时间表*/
	$("#btnBespeakTimeTable").click(function (){
		var url=ctx+"/visitor/bespeakTimeTable";
		/*iframe窗*/
		showSmallWindow('预约时间表',url,'600px', '390px');		
	});
	
	
});
function showTHeBespeak(bespeakNumber){
	if((new String(bespeakNumber)).length!=11){
		layer.msg('请填写正确的预约编码');
		return false;
	}
	showBespeakDetail(bespeakNumber);
}
/**预约人信息详情展示-获取数据*/
function showBespeakDetail(bespeakNumber){
	$("#showMsg01").css("display","block");
	if(""!=bespeakNumber){
		 if(!(/^\d+$/.test(bespeakNumber))) {
			 layer.tips('请填写正确的预约编码', '#searchBespeakNumber', {
			  tips: [1, '#0FA6D8'] 
			 });
			 $("#showMsg01").css("display","none");
//			 return "0";
			 return false;
		 }
	}
	var ctx=$("#inputCtx").val();
	$.ajax({
		url:ctx+"/visitor/search?bespeakNumber="+bespeakNumber,
		type:"post",
		async:false,
		success:function(data){ 
			if("noOne"===data){
				$("#showMsg01").css("display","none");
				layer.msg('该预约编号不存在');
			}else if("false"===data){
				$("#showMsg01").css("display","none");
				layer.msg('请填写正确的预约编码');
			}else{
				var obj = eval("("+data+")");
			/*预约人姓名*/
//			var stmp="律师姓名:<c:out value='"+obj.bespeakName+"'></c:out>";
				var stmp="预约人姓名:"+obj.bespeakName;
				$("#showDetail01").html(stmp);
			/*预约人证件*/
				stmp=obj.bespeakCredentials;
				$("#showDetail02").attr("src",stmp);
			/*嫌犯姓名*/
//			stmp="嫌犯姓名:<c:out value='"+obj.suspectName+"'></c:out>";
				stmp="嫌犯姓名:"+obj.suspectName;
				$("#showDetail03").html(stmp);
			/*嫌犯附件证明*/
				stmp=obj.suspectAttachment;
				$("#showDetail04").attr("src",stmp);
			/*嫌犯身份证号*/
				stmp=obj.suspectCredentialsNumber;
				$("#showDetail05").html(stmp);
			/*预约时间*/
				stmp=(obj.bespeakStart.year+1900)+
				"-"+obj.bespeakStart.month+
				"-"+obj.bespeakStart.date+
				" "+obj.bespeakStart.hours+
				":"+obj.bespeakStart.minutes+
				"~"+obj.bespeakEnd.hours+
				":"+obj.bespeakEnd.minutes;
				$("#showDetail06").html(stmp);
//				return "1";
			}
		}
	});
}
/*将json里的时间转换成正常格式*/
//function json2TimeStamp(milliseconds){
//   var datetime = new Date();
//   datetime.setTime(milliseconds);
//   var year=datetime.getFullYear();
        /*月份重0开始，所以要加1，当小于10月时，为了显示2位的月份，所以补0*/
//   var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
//   var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
//   return year + "-" + month + "-" + date;
//}
/**预约人信息详情展示--弹层*/
function showSmallWindow(title,url,x,y){
	layer.open({
      type: 2,
      title: title,
      shadeClose: false,
      shade: 0.6,
      /*开启最大化最小化按钮*/
      maxmin: false, 
      area: [x,y],
      content: [url,'no']
    });
}